﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;
public partial class page_EditForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Message.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 18)
                    {
                        userFlag = true;
                        break;
                    }
                }
            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
        }
        if(!IsPostBack)
        {
            string id = Request["id"].ToString();
            Flow_EditForm fef = new Flow_EditForm();
            FreeTextBox1.value = fef.getFlowForm(id);
        }

    }
    protected void BtnEditForm_Click(object sender, EventArgs e)
    {
        string id = Request["id"].ToString();
        Flow_EditForm fef = new Flow_EditForm();
        string str = FreeTextBox1.value;
        str = str.Replace("type=checkbox", "type=checkbox value=on");
        fef.editFlowForm(id,str);
        
        this.WriteFile(id,FreeTextBox1.value);

    }
    public void WriteFile(string filename, string deatil)
    {

        string path = Server.MapPath(".") + "\\flow_forms\\" + filename + ".txt";
        //先删除文件
        if (System.IO.File.Exists(path))
        {
            System.IO.File.Delete(path);
        }
        if (!System.IO.File.Exists(path))
        {
            System.IO.FileStream f = System.IO.File.Create(path);
            f.Close();
        }
        System.IO.StreamWriter f2 = new System.IO.StreamWriter(path, true, System.Text.Encoding.GetEncoding("gb2312"));
        f2.WriteLine(deatil);
        f2.Close();
        f2.Dispose();
    }
}
